import { undoX } from '@/api/common'
import UtilsDate from "@/utils/date";
import { MessageBox } from 'element-ui'

function cancelFunc(data) {
  // MessageBox.confirm('请确认是否撤销？', '撤销', {
  //   type: 'warning',
  //   confirmButtonText: '确定',
  //   cancelButtonText: '取消',
  // }).then(() => {
  //   return new Promise((resolve, reject) => {
  //     undoX(data).then((res) => {
  //       if (res.code === 200) {
  //         resolve()
  //       } else {
  //         reject(res.msg)
  //       }
  //     })
  //   })
  // })
  return new Promise((resolve, reject) => {
    undoX(data).then((res) => {
      if (res.code === 200) {
        resolve()
      } else {
        reject(res.msg)
      }
    })
  })
}

var meetingType = {
  ProjectResolution: 1,   //立项决议
  SchemeReview: 2,        //方案评审
  PlanReview: 3,          //计划评审
  TaskAcceptance: 4,      //任务验收
  ProjectAcceptance: 5,   //项目验收
  PeriodicReview: 6,      //阶段性评审
}

function goMeetingCreate(type, data, d_data) {
  let business = ""
  for (let key in meetingType) {
    if (meetingType[key] == type) {
      business = key
    }
  }
  let information = "Project"
  if (type == meetingType.ProjectResolution) {
    information = "SelfResearchProject"
  }
  let ruleForm = {
    name: '',//会议名称
    type: "Resolution",//会议类型
    discussion: "", //会议议题输入的
    resolutionBusiness: business, //决议事务
    relatedInformation: information, //相关信息
    meetingCreateUser: "", //会议发起人
    startTime: new Date(UtilsDate.getDay(1)), //开始时间
    endTime: new Date(UtilsDate.getDay(2)), //结束时间
    meetingRoomId: "", //会议室id 如果选择了会议室的话
    meetingRoomName: "", //会议室地址手动输入的
    joinStaffList: [], //参与会议人员
    hostStaff: {}, //会议主持人
    recorderStaff: "", //会议记录员
    projectName: data.name, //项目名称
    projectId: data.id, //项目ID
    taskName: d_data ? d_data.name : "", //任务名称
    taskId: d_data ? d_data.id : "", // 任务ID
    template: {
      Files: [],
    },
  };

  localStorage.setItem('ruleForm', JSON.stringify(ruleForm))

  //history.pushState("","","/yiyaoVue/work/meeting/add?type=ipd")
  console.log(window.location.host)
  window.open('http://' + window.location.host + "/yiyaoVue/work/meeting/add?type=ipd");
}

function goMeetingAdd() {
  //history.pushState("","","/yiyaoVue/work/meeting/add")
  console.log(window.location.host)
  window.open('http://' + window.location.host + "/yiyaoVue/work/meeting/add");
}

function goMeetingView(id) {
  // history.pushState("","","/yiyaoVue/work/meeting/detail?item=" + id)
  window.open('http://' + window.location.host + "/yiyaoVue/work/meeting/detail?item=" + id);
}

export default { cancelFunc, goMeetingView, goMeetingCreate, goMeetingAdd }
